package com.itheima.controller.backend.Controller;

import com.itheima.VO.ReportDataVO;
import com.itheima.VO.ReportVO;
import com.itheima.common.entity.Result;
import com.itheima.controller.backend.Service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
@Api(tags = "统计接口")
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @ApiOperation("获取会员数量统计数据")
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        log.info("获取会员数量统计数据");
        Map map = reportService.getMemberReport();
        return new Result(true,"获取会员数量统计数据成功",map);
    }

    @GetMapping("/getSetmealReport")
    @ApiOperation("获取套餐占比统计数据")
    public Result getSetmealReport(){
        log.info("获取套餐占比统计数据");
        ReportVO reportVO =  reportService.getSetmealReport();
        return new Result(true,"获取套餐占比统计数据成功",reportVO);
    }

    @GetMapping("/getBusinessReportData")
    @ApiOperation("获取运营统计数据")
    public Result getBusinessReportData(){
        log.info("获取运营统计数据");
        ReportDataVO reportDataVO = reportService.getBusinessReportData();
        return new Result(true,"获取运营统计数据成功",reportDataVO);
    }

    @GetMapping("/exportBusinessReport")
    @ApiOperation("导出运营数据到Excel并提供客户端下载")
    public String exportBusinessReport(HttpServletResponse response) throws Exception{
        log.info("导出运营数据到Excel并提供客户端下载");
        reportService.excel(response);
        return "下载文件";
    }

}
